package ee.karileet.productcatalogue.dao.impl;

// Generated Dec 1, 2013 7:35:28 PM by Hibernate Tools 3.4.0.CR1

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.criterion.SimpleExpression;

import ee.karileet.productcatalogue.dao.IAttributeHome;
import ee.karileet.productcatalogue.model.Attribute;
import static org.hibernate.criterion.Example.create;

/**
 * Home object for domain model class Attribute.
 * @see ee.karileet.productcatalogue.model.Attribute
 * @author Hibernate Tools
 */
public class AttributeHome extends GenericHome implements IAttributeHome {
	private static final Log log = LogFactory.getLog(AttributeHome.class);

	public AttributeHome() {
		super("ee.karileet.productcatalogue.model.Attribute");
	}
	
	public void persist(Attribute transientInstance) {
		log.debug("persisting Attribute instance");
		try {
			sessionFactory.getCurrentSession().persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(Attribute instance) {
		log.debug("attaching dirty Attribute instance");
		try {
			sessionFactory.getCurrentSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	@SuppressWarnings("deprecation")
	public void attachClean(Attribute instance) {
		log.debug("attaching clean Attribute instance");
		try {
			sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(Attribute persistentInstance) {
		log.debug("deleting Attribute instance");
		try {
			sessionFactory.getCurrentSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Attribute merge(Attribute detachedInstance) {
		log.debug("merging Attribute instance");
		try {
			Attribute result = (Attribute) sessionFactory.getCurrentSession()
					.merge(detachedInstance);
			log.debug("merge successful");	
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public Attribute findById(int id) {
		log.debug("getting Attribute instance with id: " + id);
		try {
			Attribute instance = (Attribute) sessionFactory.getCurrentSession()
					.get(entityName, id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	@SuppressWarnings("unchecked")
	public List<Attribute> findByExample(Attribute instance) {
		log.debug("finding Attribute instance by example");
		try {
			List<Attribute> results = (List<Attribute>) sessionFactory
					.getCurrentSession()
					.createCriteria(
							entityName)
					.add(create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	@SuppressWarnings("unchecked")
	public List<Attribute> find(List<SimpleExpression> expressions) {
		return (List<Attribute>) super.find(entityName, expressions);
	}

	@SuppressWarnings("unchecked")
	public List<Attribute> findAll() {
		return (List<Attribute>) super.findAll(entityName);
	}

	@Override
	public void save(Attribute attribute) {
		super.save(attribute);
	}

}
